<template>

  <el-select
    v-model="classesId"

    placeholder="请选择班级"
    filterable
    clearable
    :disabled="disabled"
  >
    <el-option
      v-for="dict in classesList"
      :key="dict.id"
      :label="dict.classesName"
      :value="dict.id"
    />
  </el-select>


</template>

<script>
import common from "@/api/collegebase/common";

export default {
  name: "ClassesFromSelector",
  props: {
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    professionId: {
      type: String,
      default: ''
    },
  }
  ,
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      classesList: [],
      classesId: '',
    };
  },

  created() {
  },

  watch: {
    classesId(value) {
      this.$emit('change', value)
    },
    value(value) {
      this.classesId = value;
    },

    professionId: {
      immediate: true,
      handler(newVal, oldVal) {
        if (oldVal) {
          this.classesId = '';
        } else {
          this.classesId = this.value;
        }

        this.getClassesData(newVal)
      }
    },
  },
  methods: {
    //获取学院
    async getClassesData(collegeId) {
      if (null == collegeId || '' == collegeId) {
        this.classesList = []
        return;
      }
      const classesList = await common.getClassesList(collegeId);
      this.classesList = classesList.data;
    }

  }


}
</script>

